// https://leetcode.cn/problems/ambiguous-coordinates/
// Created by ade on 2022/11/7.
//
#include <vector>
#include <iostream>
#include <string>

using namespace std;

class Solution {
public:
    vector <string> ambiguousCoordinates(string s) {
        s = s.substr(1, s.size() - 2);
        vector <string> res = {};
        for (int i = 1; i < s.size(); i++) {
            vector <string> v1 = {};
            vector <string> v2 = {};
            combine(v1, s.substr(0, i));
            combine(v2, s.substr(i));
            for (int i = 0; i < v1.size(); i++) {
                if (isBadString(v1[i])) continue;
                for (int j = 0; j < v2.size(); j++) {
                    if (isBadString(v2[j])) continue;
                    res.push_back("(" + v1[i] + ", " + v2[j] + ")");
                }
            }
        }
        return res;
    }

    void combine(vector <string> &res, string s) {
        for (int i = 1; i <= s.size(); i++) {
            string tmp = s.substr(0, i);
            if (i == s.size())
                res.push_back(tmp);
            else
                res.push_back(tmp + "." + s.substr(i));
        }
    }

    // 真正的难点是这个函数
    bool isBadString(string &s) {
        if (s.size() == 1) return false;
        return s[0] == '0' && s[1] != '.'
               || s.find('.') != string::npos && s.back() == '0';
    }

    void show(vector <string> &res) {
        for (auto &i:res) {
            cout << i << ",";
        }
        cout << endl;
    }
};

int main() {
    Solution so;
//    string s = "100";
//    cout << s.substr(s.size() - 2,2) << endl;
//    return 0;
    auto res = so.ambiguousCoordinates("(00011)");
    so.show(res);
    return 0;
}